package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.entity.Orders;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.impl.OrderServiceImpl;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.print.attribute.standard.ReferenceUriSchemesSupported;

@RestController("adminorderController")
@RequestMapping("/admin/order")
@Api(tags = "管理端订单接口")
public class OrderController {
    @Autowired
    private OrderServiceImpl orderServiceImpl;
    @ApiOperation("查询订单详情")
    @GetMapping("/conditionSearch")
    Result<PageResult>ConditionSearch(Integer page, Integer pageSize, String number, String beginTime, String endTime, Integer status,String phone){
        //number是订单号，ststus是订单状态,beginTime和endTime表示在这个范围内的订单下单时间
        PageResult pageResult = orderServiceImpl.pageQuery(page, pageSize, number, beginTime, endTime, status,phone);
        return Result.success(pageResult);
    }
    @ApiOperation("各个订单数量统计")
    @GetMapping("/statistics")
    public Result<OrderStatisticsVO> statistics(){
        OrderStatisticsVO orderStatisticsVO = orderServiceImpl.statistics();
        return Result.success(orderStatisticsVO);
    }

    //查看订单详情
    @GetMapping("/details/{id}")//获得订单id
    @ApiOperation("查看订单详情")
    public Result<OrderVO>details(@PathVariable Long id){
        OrderVO orderVO = orderServiceImpl.details(id);
        return Result.success(orderVO);
    }
    @ApiOperation("取消订单")
    @PutMapping("/cancel")
    public Result cancel(@RequestBody OrdersCancelDTO  ordersCancelDTO){
        orderServiceImpl.cancel2(ordersCancelDTO);
        return Result.success();
    }
    @ApiOperation("商家接单")
    @PutMapping("/confirm")
    public Result confirm(@RequestBody OrdersDTO ordersDTO){
        orderServiceImpl.confirm(ordersDTO);
        return Result.success();
    }
    @ApiOperation("订单派送")
    @PutMapping("/delivery/{id}")
    public Result delivery(@PathVariable Long id){
        orderServiceImpl.delivery(id);
        return Result.success();
    }
    @ApiOperation("订单完成")
    @PutMapping("/complete/{id}")
    public Result complete(@PathVariable Long id){
        orderServiceImpl.complete(id);
        return Result.success();
    }
    @ApiOperation("订单拒绝")
    @PutMapping("/rejection")
    public Result rejection(@RequestBody OrdersRejectionDTO ordersRejectionDTO){
        orderServiceImpl.rejection(ordersRejectionDTO);
        return Result.success();
    }
}
